#ifndef WATER_H_
#define WATER_H_
#include "../generic/Object.h"
#include "../generic/Vertex.h"
#include "PerlinNoise.h"

#define TEXTURE_WATER_COUNT 10

class Camera;
class Water : public Object
{
public:
	Water();
	virtual ~Water();
		
/* Attributes ================= */
private:
	int width; //Perlin noise width
	int height;
	int waterWidth; //Water width, tiled by perlin noise heighmap, for correct normal calculation
	int waterHeight;
	
	GLuint* textures;
	float scaleX;
	float scaleY;
	float downY;
	
	//Animation
	int offset;
	
	float sinWave;
	float sinCoefficient;
	
	//Camera
	Camera* camera;	
/* ============================ */	
	
private:	
	void LoadWater();
public:
	void GetSize(float & width, float & height);
	void Update(long time);
	void RenderWater();
	void RenderInfinite();
	void Render();
	
/* Water simulation ========================== */
private:
	PerlinNoise* perlin;
	GLubyte* perlinHeightmap;
	void CreatePerlinHeightmap2d();
	void CreatePerlinHeightmap3d(float time);
		
	void SavePerlinHeightmap(int dimension, int i);
	void SeparatePerlinHeightmap();
	
protected: 
	/* vertex */
	Vertex* vertice; //triangle strip
	int numVertice;
public:
	void LoadVertice();
	void RenderPerlinNoise();
};

#endif /*WATER_H_*/
